package fybug.nulll.pdstream.WR.Parsing.Source;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Reader;

import fybug.nulll.pdstream.WR.Parsing.Source.Partition.ParsingPartition;

import static fybug.nulll.pdstream.StreamOperator.toBufferStream;
import static fybug.nulll.pdstream.WR.Parsing.Source.Partition.ParsingPartitionS.getLinePartition;
import static fybug.nulll.pdstream.WR.Parsing.Source.Partition.ParsingPartitionS.getPartition;
import static fybug.nulll.pdstream.WR.Parsing.Source.Partition.ParsingPartitionS.getTablePartition;
/**
 * <h2>文本解析源工场.</h2>
 * <pre>
 * 用于构造 <b>文本解析器</b>的解析源,并包装为 <b>缓冲流</b>
 *
 * 内置:
 * {@link #creatLineSoure(CharSequence)} 行解析器
 * {@link #creatTableSoure(CharSequence)} 表单解析器
 * </pre>
 *
 * @author fybug
 * @version 0.0.4
 * @see ParsingPartition
 * @see ParsingSource
 * @since JDK 1.8
 */
@SuppressWarnings( "All" )
public final
class ParsingSourceS {
    /** {@Hide} */
    @Deprecated
    private
    ParsingSourceS() {}

    /*
     * MainSoure
     */

    /**
     * <p>使用字符串构造一个解析源.</p>
     * <pre>
     * 需传入分隔符
     * </pre>
     *
     * @param s       要解析的字符串
     * @param parsing 分隔符
     */
    @NotNull
    public static
    ParsingSource creatSoure(@NotNull final CharSequence s, @Nullable final CharSequence... parsing)
    { return new ParsingSource(String.valueOf(s), getPartition(parsing)); }

    /**
     * <p>使用字符读取流构造一个解析源.</p>
     * <pre>
     * 需传入分隔符
     * </pre>
     */
    @NotNull
    public static
    ParsingSource creatSoure(@NotNull final Reader reader, @Nullable final CharSequence... parsing)
    { return new ParsingSource(toBufferStream(reader, 8192), getPartition(parsing)); }

    /**
     * <p>使用字节读取流构造一个解析源.</p>
     * <pre>
     * 需传入分隔符
     * </pre>
     */
    @NotNull
    public static
    ParsingSource creatSoure(@NotNull final InputStream reader,
            @Nullable final CharSequence... parsing)
    { return new ParsingSource(reader, getPartition(parsing)); }

    /**
     * <p>构造一个文本文件解析源.</p>
     * <pre>
     * 需传入分隔符
     * </pre>
     */
    @NotNull
    public static
    ParsingSource creatSoure(@NotNull final File reader, @Nullable final CharSequence... parsing)
    throws FileNotFoundException
    { return new ParsingSource(new FileInputStream(reader), getPartition(parsing)); }

    /*
     * LineSoure
     */

    /** <p>使用字符串构造一个行解析源.</p> */
    @NotNull
    public static
    ParsingSource creatLineSoure(@NotNull final CharSequence s)
    { return new ParsingSource(String.valueOf(s), getLinePartition()); }

    /** <p>使用字符读取流构造一个行解析源.</p> */
    @NotNull
    public static
    ParsingSource creatLineSoure(@NotNull final Reader reader)
    { return new ParsingSource(toBufferStream(reader, 8192), getLinePartition()); }

    /** <p>使用字节读取流构造一个行解析源.</p> */
    @NotNull
    public static
    ParsingSource creatLineSoure(@NotNull final InputStream reader)
    { return new ParsingSource(reader, getLinePartition()); }

    /** <p>构造一个逐行解析文本文件的解析源.</p> */
    @NotNull
    public static
    ParsingSource creatLineSoure(@NotNull final File reader) throws FileNotFoundException
    { return new ParsingSource(new FileInputStream(reader), getLinePartition()); }

    /*
     * TableSoure
     */

    /** <p>使用字符串构造一个表单解析源.</p> */
    @NotNull
    public static
    ParsingSource creatTableSoure(@NotNull final CharSequence s)
    { return new ParsingSource(String.valueOf(s), getTablePartition()); }

    /** <p>使用字符读取流构造一个表单解析源.</p> */
    @NotNull
    public static
    ParsingSource creatTableSoure(@NotNull final Reader reader)
    { return new ParsingSource(toBufferStream(reader, 8192), getTablePartition()); }

    /** <p>使用字节读取流构造一个表单解析源.</p> */
    @NotNull
    public static
    ParsingSource creatTableSoure(@NotNull final InputStream reader)
    { return new ParsingSource(reader, getTablePartition()); }
}
